#include <iostream>

#include "affinity_id_generator_range.h"

namespace AceMesh_runtime
{
affinity_id_generator_range::affinity_id_generator_range(int thread_nums) : id(0), start(0), end(thread_nums) {}

affinity_id_generator_range::affinity_id_generator_range(int start, int end) : id(start), start(start), end(end) {}

affinity_id_generator_range::affinity_id_generator_range() : id(0), start(0), end(0) {}

affinity_id_generator_range::~affinity_id_generator_range() {}

int affinity_id_generator_range::get_affinity_id()
{
    int res = id;
    ++id;
    if (id == end) {
        id = start;
    }
    //printf("rang_get_affinity_id=%d,start=%d,end=%d\n",res,start,end);
    return res;
}
#if defined(AGENT_COMPU)
void affinity_id_generator_range::set_thread_num(int thread_nums) { end = start + thread_nums; }
#else
void affinity_id_generator_range::set_thread_num(int thread_nums) { end = start + thread_nums-1; }
#endif

void affinity_id_generator_range::set_sub_affinity(int startid, int size) {
    start = startid;
    end = start + size;
    id = start;
    //printf("affinity_generator_get_affinity=%d,%d,start=%d,end=%d,id=%d\n",startid,size,start,end,id);
    //fflush(stdout);
}

void affinity_id_generator_range::reset_affinity_id() { id = start; }
}  // namespace AceMesh_runtime
